package design_pattern.iterator;

import java.util.List;

public class ProductList extends AbstractObjectList {
    public ProductList(List<Object> products) {
        super(products);
    }

    @Override
    public AbstractIterators createIterators() {
        return new ProductIterator();
    }


    private class ProductIterator implements AbstractIterators {
        public int cursor1;
        public int cursor2;

        public ProductIterator() {
            this.cursor1 = 0;
            this.cursor2 = objects.size() - 1;
        }

        @Override
        public void next() {
            if (cursor1 < objects.size()) {
                cursor1++;
            }
        }

        @Override
        public boolean isLast() {
            return cursor1 == objects.size();
        }

        @Override
        public void previous() {
            if (cursor2 > -1) {
                cursor2--;
            }
        }

        @Override
        public boolean isFirst() {
            return cursor2 == -1;
        }

        @Override
        public Object getNextItem() {
            return objects.get(cursor1);
        }

        @Override
        public Object getPreviousItem() {
            return objects.get(cursor2);
        }
    }
}
